﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Shapes;
using GBlason.ViewModel.Contract;

namespace GBlason.Common.Tools
{
    public class BindingManager
    {
        /// <summary>
        /// Creates the and bind path.
        /// </summary>
        /// <param name="fromThisElement">From this element.</param>
        /// <returns></returns>
        public static Path CreateAndBindPath(CoatOfArmComponent fromThisElement)
        {
            var path = new Path();
            if (fromThisElement == null) return path;

            //Binding by Interface, IShapable = Geometry / Data
            {
                var bindingPath = new Binding
                   {
                       Source = fromThisElement,
                       Path = new PropertyPath("Geometry"),
                       Mode = BindingMode.OneWay
                   };
                path.SetBinding(Path.DataProperty, bindingPath);
            }

            //IFillable = Color / Fill
            if (fromThisElement is IFillable)
            {
                var bindingPath = new Binding
                {
                    Source = fromThisElement,
                    Path = new PropertyPath("ColorFill.Color"),
                    Mode = BindingMode.OneWay
                };
                path.SetBinding(Shape.FillProperty, bindingPath);
            }
            return path;
        }
    }
}
